package com.zhao;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result {
    private Boolean success;
    private Integer code;
    private String message;
    private Map data=new HashMap();

    private Result(){}

    public static Result ok(){
        Result result=new Result();
        result.setCode(ResultCode.success);
        result.setSuccess(true);
        result.setMessage("操作成功");
        return result;
    }
    public static Result error(){
        Result result=new Result();
        result.setCode(ResultCode.error);
        result.setSuccess(false);
        result.setMessage("操作失败");
        return result;
    }

    public Result success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public Result message(String message){
        this.setMessage(message);
        return this;
    }

    public Result code(Integer code){
        this.setCode(code);
        return this;
    }

    public Result data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public Result data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}
